from __future__ import absolute_import
import xadmin
from xadmin import views
from .models import UserSettings, Log
# from django.contrib.auth.admin import UserAdmin
from xadmin.layout import *
from django.utils.translation import ugettext_lazy as _, ugettext

class UserSettingsAdmin(object):
    '''
    default
    the primary navigation:administration > usersetting
    默认情况下 该管理器是 "管理" 下 的 "用户设置"
    '''
    model_icon = 'fa fa-cog'
    # model_icon = 'fa fa-handshake-o'
    # hidden_menu = True

xadmin.site.register(UserSettings, UserSettingsAdmin)

class LogAdmin(object):
    '''
        default
        the primary navigation:administration > log entries
        默认情况下 该管理器是 "管理" 下 的 "日志记录"
        '''
    def link(self, instance):
        if instance.content_type and instance.object_id and instance.action_flag != 'delete':
            admin_url = self.get_admin_url('%s_%s_change' % (instance.content_type.app_label, instance.content_type.model), 
                instance.object_id)
            return "<a href='%s'>%s</a>" % (admin_url, _('Admin Object'))
        else:
            return ''
    link.short_description = ""
    link.allow_tags = True
    link.is_column = False

    list_display = ('action_time', 'user', 'ip_addr', '__str__', 'link')
    list_filter = ['user', 'action_time']
    search_fields = ['ip_addr', 'message']
    model_icon = 'fa fa-cog'
    # model_icon = 'fa fa-microchip'
xadmin.site.register(Log, LogAdmin)


# 全局配置
from apps.adminx import *

